from enum import Enum
from sqlalchemy import Column, Integer, String, Date, Text
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Enum as SQLEnum

Base = declarative_base()


# 性别枚举（使用字符串值）
class Gender(str, Enum):
    MALE = '男'
    FEMALE = '女'


# 糖尿病类型枚举（使用字符串值）
class DiabetesType(str, Enum):
    TYPE_1 = '1型'
    TYPE_2 = '2型'
    GESTATIONAL = '妊娠期糖尿病'
    OTHER = '其他特殊类型'


# 吸烟状态枚举（使用字符串值）
class SmokingStatus(str, Enum):
    SMOKING = '吸烟'
    QUIT = '已戒烟'
    NEVER = '从不吸烟'


# 饮酒状态枚举（使用字符串值）
class DrinkingStatus(str, Enum):
    DRINKING = '饮酒'
    NOT_DRINKING = '不饮酒'


# 糖尿病患者模型
class DiabetesPatient(Base):
    __tablename__ = 'diabetes_patients'

    id = Column(Integer, primary_key=True, index=True)
    name = Column(String(50), nullable=False)
    gender = Column(String(10), nullable=False)  # 改为String类型存储
    age = Column(Integer, nullable=False)
    contact = Column(String(20), nullable=False)
    id_card = Column(String(18), nullable=False, unique=True)
    address = Column(String(200), nullable=False)
    diagnosis_date = Column(Date, nullable=False)
    diabetes_type = Column(String(20), nullable=False)  # 改为String类型存储
    diet = Column(Text)
    smoking_status = Column(String(10))  # 改为String类型存储
    drinking_status = Column(String(10))  # 改为String类型存储

    # 添加枚举属性（方便代码中使用枚举）
    @property
    def gender_enum(self):
        return Gender(self.gender)

    @property
    def diabetes_type_enum(self):
        return DiabetesType(self.diabetes_type)

    @property
    def smoking_status_enum(self):
        return SmokingStatus(self.smoking_status) if self.smoking_status else None

    @property
    def drinking_status_enum(self):
        return DrinkingStatus(self.drinking_status) if self.drinking_status else None